package com.lz.hotel_java.controller;

import com.lz.hotel_java.entity.BookingRes;
import com.lz.hotel_java.entity.Customer;
import com.lz.hotel_java.entity.Booking;
import com.lz.hotel_java.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/booking")
@CrossOrigin("*")
public class BookingController {
    @Autowired
    private BookingService bookingService;

    @PostMapping("/reserve/{roomId}")
    public String reserve(@RequestBody Customer customer, @PathVariable Integer roomId) {
        boolean success = bookingService.reserveRoom(customer, roomId);
        return success ? "预订成功" : "预订失败";
    }

    @GetMapping("/booked")
    public java.util.List<Booking> getBookedRooms() {
        return bookingService.getBookedRooms();
    }

    @GetMapping("/all")
    public java.util.List<BookingRes> getAllBooked() {
        return bookingService.getAll();
    }

    @PostMapping("/checkin")
    public String checkIn(@RequestBody Booking booking) {
        boolean success = bookingService.checkIn(booking);
        return success ? "入住成功" : "入住失败";
    }

    @PostMapping("/checkout")
    public String checkOut(@RequestBody Booking booking) {
        boolean success = bookingService.checkOut(booking);
        return success ? "退房成功" : "退房失败";
    }

    @PostMapping("/cancel")
    public String cancel(@RequestBody Booking booking) {
        boolean success = bookingService.cancel(booking);
        return success ? "取消成功" : "取消失败";
    }
}
